/*****************************************************************************
	SNEGA UTILITIES 0.7a
	Copyright (C) 2009, Xiaohan Tian (snega0223)
	
	http://code.google.com/p/snega-utilities/
	
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License(LGPL) as
	published by the Free Software Foundation, either version 3 of the 
	License, or(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

package org.sng.util.db.rawsql;

import org.sng.util.db.*;
import org.sng.util.db.rawsql.cond.*;
import org.sng.util.db.rawsql.target.*;

/**
 * @author Xiaohan Tian
 *
 */
public class RawSQL {
	
	protected Condition m_cond;
	protected Target m_target;
	
	protected GeneralOpForDatabase m_dbo;
	
	protected RawSQL()
	{
		this.m_cond = new Condition();
		this.m_target = new Target();
		
		this.m_dbo = null;
	}
	
	protected RawSQL(String s)
	{
		this.m_cond = new Condition();
		this.m_target = new Target(s);
		
		this.m_dbo = null;
	}
	
	public DbConn Execute()
	{
		return null;
	}
	
	public GeneralOpForDatabase GetDbo()
	{
		return this.m_dbo;
	}
	
	public void SetDbo(GeneralOpForDatabase dbo)
	{
		this.m_dbo = dbo;
	}
	
	public Target GetTarget()
	{
		return this.m_target;
	}
	
	public Condition GetCondition()
	{
		return this.m_cond;
	}
	
	/* ------ Static Methods ------ */
	/*public static SQLSelect CreateSelect()
	{
		return new SQLSelect();
	}*/
	
	public static SQLSelect CreateSelect(String s)
	{
		return new SQLSelect(s);
	}
	
	/*public static SQLInsert CreateInsert()
	{
		return new SQLInsert();
	}*/
	
	public static SQLInsert CreateInsert(String s)
	{
		return new SQLInsert(s);
	}
	
	/*public static SQLUpdate CreateUpdate()
	{
		return new SQLUpdate();
	}*/
	
	public static SQLUpdate CreateUpdate(String s)
	{
		return new SQLUpdate(s);
	}
	
	/*public static SQLDelete CreateDelete()
	{
		return new SQLDelete();
	}*/
	
	public static SQLDelete CreateDelete(String s)
	{
		return new SQLDelete(s);
	}
	
	/* ------ Additional Target ------ */
	public RawSQL AppendTarget(String s)
	{
		this.m_target.AppendTarget(new Target(s));
		
		return this;
	}
	
	/* ------ Output ------ */
	public String ToSQL()
	{
		StringBuffer sb = new StringBuffer();
		
		return sb.toString();
	}
	
	/* ------ Additional Conditions ------ */
	public RawSQL WhereEquare(String s, int n)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.EQUARE, s, String.valueOf(n)));
		
		return this;
	}
	
	public RawSQL WhereEquare(String s, double d)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.EQUARE, s, String.valueOf(d)));
		
		return this;
	}
	
	public RawSQL WhereEquare(String s, String compare)
	{
		this.m_cond.AppendCondition(new ConditionForString(Compare.EQUARE, s, compare));
		
		return this;
	}
	
	public RawSQL WhereNotEquare(String s, int n)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.NOTEQUARE, s, String.valueOf(n)));
		
		return this;
	}
	
	public RawSQL WhereNotEquare(String s, double d)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.NOTEQUARE, s, String.valueOf(d)));
		
		return this;
	}
	
	public RawSQL WhereNotEquare(String s, String compare)
	{
		this.m_cond.AppendCondition(new ConditionForString(Compare.NOTEQUARE, s, compare));
		
		return this;
	}
	
	public RawSQL WhereBigger(String s, int n)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.BIGGER, s, String.valueOf(n)));
		
		return this;
	}
	
	public RawSQL WhereBigger(String s, double d)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.BIGGER, s, String.valueOf(d)));
		
		return this;
	}
	
	public RawSQL WhereBigger(String s, String compare)
	{
		this.m_cond.AppendCondition(new ConditionForString(Compare.BIGGER, s, compare));
		
		return this;
	}
	
	public RawSQL WhereSmaller(String s, int n)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.SMALLER, s, String.valueOf(n)));
		
		return this;
	}
	
	public RawSQL WhereSmaller(String s, double d)
	{
		this.m_cond.AppendCondition(new ConditionForNumber(Compare.SMALLER, s, String.valueOf(d)));
		
		return this;
	}
	
	public RawSQL WhereSmaller(String s, String compare)
	{
		this.m_cond.AppendCondition(new ConditionForString(Compare.SMALLER, s, compare));
		
		return this;
	}
}
